import { Component, OnInit } from '@angular/core';
import { JiluService } from '../../services/jilu.service';
import { CommonService } from '../../services/common.service';
import { HttpClient, HttpHeaders, HttpClientJsonpModule } from '@angular/common/http';

@Component({
  selector: 'app-aiqing',
  templateUrl: './aiqing.component.html',
  styleUrls: ['./aiqing.component.css']
})
export class AiqingComponent implements OnInit {

  public keyword: string;
  public historyList: any[] = [];
  private list: any[] = [];
  private huoqulist: any[] = [];
  private main: string = "http://10.100.185.117:4200/";
  private jiazailist: any[] = [];
  public num=1;


  constructor(public storage: JiluService,
    public common: CommonService,
    public Http: HttpClient
  ) { }


  ngOnInit() {

    var api = "/hello/";
    this.common.get(api).then((response: any) => {
      console.log(response);
      this.list = response.result1;
    })

    var searchlist = this.storage.get('searchlist');
    if (searchlist) {
      this.historyList = searchlist;


    }


  }

  doSearch() {

    if (this.historyList.indexOf(this.keyword) == -1) {

      this.historyList.push(this.keyword);

      this.storage.set('searchlist', this.historyList);

    }
    this.keyword = '';
    console.log({ "moviename": this.historyList });
    const httpOptions = {
      headers: new HttpHeaders({
        'Content-Type': 'application/json;charset=UTF-8',
        'Access-Control-Allow-Origin': '*',
      })
    };
    var api = "http://10.100.185.117:4200/love";
    this.Http.post(api, { "moviename": this.historyList[this.historyList.length - 1] }, httpOptions).subscribe((response: any) => {

      console.log(response);
      this.huoqulist = response.result1;

    })


  }

  deleteHistroy(key) {

    this.historyList.splice(key, 1);
    this.storage.set('searchlist', this.historyList);
  }
  
jiazai(){
    
  console.log({"num":"number"});
  const httpOptions = {
    headers: new HttpHeaders({
      'Content-Type': 'application/json;charset=UTF-8',
      'Access-Control-Allow-Origin': '*',
    })
  };
  var api = "http://10.100.185.117:4200/suspense";
  this.Http.post(api, {"num":this.num}, httpOptions).subscribe((response: any) => {
    this.num=this.num+1;
    console.log(response);
    this.jiazailist = response.result1;
    
  })   
}


}